
    

products=[[ "iphone" ,6888],[ "MacPro" ,14800],[ "小米6" ,2499],[ "Coffee" ,31],
          [ "Book" ,60],[ "Nike" ,699]]

print('-'*6,"商品列表",'-'*6,sep=' '*2)
shop=[]

for i in range(len(products)):
    #print(products[i])
    for j in range(len(products[i])):
        if j==0:
            x=products[i][j]
            shop.append(x)
        else:
            
            print(shop[i],'\t',products[i][j])

flag=1
shop_car=[]
shop_cost=[]

shop.append('q')
#print(a)
pro=dict(products)
#print(pro)
number=[]
price=[]
while flag:
    
    n=input("which shop do you want to buy in the products list :\n")
    print('if shopping over ,please input "q"')
    if n not in shop:
        print("data error,please input list of products ")
        #flag=0
        continue
    

    
    if n !='q':
        try:
            num=int(input('how many of this product do you want :\n'))
        except ValueError:
            print("please input number")
            continue
        
        shop_car.append(n)
        shop_cost.append(pro[n]*num)
        price.append(pro[n])
        number.append(num)
        print(shop_car)
        print(shop_cost)
        
    if n=='q':
        flag=0
        

print('-'*6,"your shopping list",'-'*6,sep=' '*2)
print('Name','price','Number',sep='\t')

for j in range(len(shop_car)):
    print(shop_car[j],price[j],number[j],sep='\t')

print()
print('the total cost is :',sum(shop_cost))
        
    

""" 还想写个 ctrl + c 产生 KeyboardInterrupt的异常处理，但是总写的不优雅，
每次输入都要再判断一次还影响其他代码，请教下老师有什么好方式吗"""
# 信号捕获 你的这个代码运行有点问题，输入number的话应该会有个默认清单吧，0-5的清单，或者商品的名字也可以，但是没有产生预期的结果


